<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script>
		//第二种加载时不损失性能， 但是第一次调用时损失性能
		function createXHR() {
			if(typeof XMLHttpRequest != "undefined") {
				createXHR = function() {
					return new XMLHttpRequest();
				};
			} else if(typeof ActiveXObject != "undefined") {
				createXHR = function() {
					if(typeof arguments.callee.activeXString != "string") {
						var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp"],
							i = 0,
							len = versions.length;
						//遍历并设置版本
						for(; i < len; i++) {
							try {
								new ActiveXObect(versions[i]);
								arguments.callee.activeXString = versions[i];
								break;
							} catch(ex) {}
						}
					}
					console.log('ActiveXObect')
					return new ActiveXObect(arguments.callee.activeXString);
					//对不支持的浏览器抛出错误提示
				};
			} else {
				createXHR = function() {
					throw new Error("No XHR object available.");
				};
			}
			return createXHR();
		}
		console.log(createXHR())
	</script>

</html>